from typing import Any, Generic, List, Optional, TypeVar
from pydantic import BaseModel

T = TypeVar('T')


class ResponseModel(BaseModel, Generic[T]):
    """统一响应格式"""
    success: bool
    message: str
    data: T


class BaseResponse(BaseModel, Generic[T]):
    """统一响应格式"""
    code: int = 200
    message: str = "success"
    data: Optional[T] = None


class ListResponse(BaseModel, Generic[T]):
    """列表响应格式"""
    code: int = 200
    message: str = "success"
    data: List[T] = []


class PaginationResponse(BaseModel, Generic[T]):
    """分页响应格式"""
    items: List[T]
    total: int
    page: int
    size: int
    pages: int


class LegacyPaginationResponse(BaseModel, Generic[T]):
    """分页响应格式（旧版本）"""
    code: int = 200
    message: str = "success"
    data: List[T] = []
    total: int = 0
    page_no: int = 1
    page_size: int = 20
    total_pages: int = 0


class SuccessResponse(BaseModel):
    """成功操作响应格式（无数据）"""
    code: int = 200
    message: str = "success"
    data: Optional[dict] = None


class ErrorResponse(BaseModel):
    """错误响应格式"""
    code: int
    message: str
    data: Optional[dict] = None